package com.ophiux.wechat.utils;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.ophiux.wechat.model.ReFundResponse;
import com.ophiux.wechat.model.Refund;

/**
 * 异常信息对象处理、生成
 * @author chenh
 *
 */
public class ResponseDealUtil {

	/**
	 * 退款操作异常信息处理
	 * 
	 */
	public static String toRefundErrorMessage(String errorcode,String errormsg){
		
		ReFundResponse resp = new ReFundResponse();
		resp.setStatus(errorcode);
		resp.setMessage(errormsg);
		
		ObjectMapper jsonmapper = new ObjectMapper();
		
		String errorJson = null;
		try {
			errorJson = jsonmapper.writeValueAsString(resp);
		} catch (JsonProcessingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return errorJson;
		
	}
	
	/**
	 * 微信退款成功消息处理
	 */
	public static String toRefundSuccessMessage(Refund refundData){
		ReFundResponse resp = new ReFundResponse();
		resp.setStatus("200");
		resp.setMessage("微信退款成功");
		//设置退款返回数据
		resp.setRefund(refundData);
		
		ObjectMapper jsonmapper = new ObjectMapper();
		
		String errorJson = null;
		try {
			errorJson = jsonmapper.writeValueAsString(resp);
		} catch (JsonProcessingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return errorJson;
	}
	
	
	
}
